var path = require('path');
var autoprefixer = require('autoprefixer');
var precss = require('precss');
var webpack = require('webpack');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var plugins = [];
var entry = {
    app: './web/dashboard/src/index.jsx'
};
if (process.env.NODE_ENV === 'production') {
    plugins = [
        new CleanWebpackPlugin(['./web/dashboard/dist'], {
            verbose: true
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }),
        new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
    ];
    entry.vendor = ['react', 'react-router', 'moment'];
}
module.exports = {
    entry: entry,
    output: {
        publicPath: process.env.NODE_ENV !== 'production' ? 'http://192.168.1.144:8011/dashboard/dist/' : 'dashboard/dist/',
        filename: 'dashboard.bundle.js',
        path: './web/dashboard/dist'
    },
    postcss: function () {
        return {
            defaults: [precss, autoprefixer],
            cleaner: [autoprefixer({browsers: ["ios >= 7", "android >= 4.0"]})]
        };
    },
    module: {
        loaders: [
            {test: /\.js$/, loader: 'babel'},
            {
                test: /.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015', 'react']
                }
            },
            {
                test: /\.(jpe?g|png|gif|svg)$/i,
                loaders: [
                    "file?name=/img/[hash:16].[ext]",
                    "image-webpack?bypassOnDebug&optimizationLevel=9&interlaced=false"
                ]
            },
            {test: /\.css$/, loader: 'style!css!postcss'},
            {test: /\.scss$/, loader: 'style!css!postcss!sass'}
        ]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    plugins: plugins
};